package gui.custom;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.util.List;

import javax.swing.JLabel;
import javax.swing.JPanel;

import backend.rss.items.SwatchItem;
import backend.rss.items.ThemeItem;


public class SelectedSwatchPanel extends AbstractSwatchPanel
{
	private boolean hexShown;
	
	
	public SelectedSwatchPanel(ThemeItem item, Dimension swatchSize)
	{
		super(item, swatchSize);
		hexShown = false;
	}
	
	public void mouseClicked(MouseEvent e)
	{	
		//if hex is not shown, display hexes as a jlabel in the centre of each swatch
		if (!hexShown)
		{
			List<SwatchItem> swatches = getThemeItem().getSwatches();
			JLabel s1 = new AALabel(swatches.get(0).getHex());
			JLabel s2 = new AALabel(swatches.get(1).getHex());
			JLabel s3 = new AALabel(swatches.get(2).getHex());
			JLabel s4 = new AALabel(swatches.get(3).getHex());
			JLabel s5 = new AALabel(swatches.get(4).getHex());

					
			colourChecker(getSwatch1(), s1);
			colourChecker(getSwatch2(), s2);
			colourChecker(getSwatch3(), s3);
			colourChecker(getSwatch4(), s4);
			colourChecker(getSwatch5(), s5);			
			
			getSwatch1().add(s1, BorderLayout.CENTER);
			getSwatch2().add(s2, BorderLayout.CENTER);
			getSwatch3().add(s3, BorderLayout.CENTER);
			getSwatch4().add(s4, BorderLayout.CENTER);
			getSwatch5().add(s5, BorderLayout.CENTER);		
		}
		else
		{
			//note: if we add more stuff into these swatches, obviously we can't do this ...
			getSwatch1().removeAll();
			getSwatch2().removeAll();
			getSwatch3().removeAll();
			getSwatch4().removeAll();
			getSwatch5().removeAll();			
		}
		
		validate();
		repaint();
		
		hexShown = !hexShown;
	}

	private void colourChecker(JPanel swatch, JLabel label)
	{
		Color swatchBG = swatch.getBackground();
		label.setForeground(swatchBG.darker().darker().darker().darker());
	}
}
